/**
 * @projectName study-note
 * @package Visitor
 * @className Visitor.ObjectStructure
 */
package Visitor;

import java.util.ArrayList;
import java.util.List;

/**
 * ObjectStructure
 * @description 对象创建
 * @author answer_wx
 * @date 2022/7/6 16:57
 * @version 1.0
 */
public class ObjectStructure {
    private List<AbstractElement> elements = new ArrayList<>();

    public void attach(AbstractElement element) {
        elements.add(element);
    }

    public void detach(AbstractElement element) {
        elements.remove(element);
    }

    public void accept(AbstractVisitor visitor) {
        for (AbstractElement element : elements) {
            element.accept(visitor);
        }
    }
}